package nc.bs.pcm.contractbalance.bp.rule;

import nc.bs.dao.BaseDAO;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.itf.pcm.contract.pub.IContrService4Bala;
import nc.vo.pcm.contractbalance.ContractBalanceBillVO;
import nc.vo.pcm.contractbalance.ContractBalanceBodyVO;
import nc.vo.pm.proxy.PMProxy;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;

/**
 * 
 * @Author ligangm
 * @Date 2012-4-16
 * @Version NC61
 * 
 */
public class ContrOprBeforeUnApprove implements IRule<ContractBalanceBillVO> {
	private IContrService4Bala contrService4Bala;

	private IContrService4Bala getContractService() {
		if (this.contrService4Bala == null) {
			this.contrService4Bala = PMProxy.lookup(IContrService4Bala.class);
		}
		return this.contrService4Bala;
	}

	@Override
	public void process(ContractBalanceBillVO[] vos) {
		try {
			if(vos[0]!=null && vos[0].getParentVO() != null && !"4D48".equals(vos[0].getParentVO().getBill_type()) && !"4D50".equals(vos[0].getParentVO().getBill_type())){
				getContractService().unApproveBalaBill(vos[0]);
			}else{
				ContractBalanceBodyVO bvo = (ContractBalanceBodyVO)vos[0].getChildren(ContractBalanceBodyVO.class)[0];
				String pk_contr_works =  bvo.getPk_contr_works();
				String sql = " update pm_contr set BALAFLAG = '2' where pk_contr in ( select pk_contr from pm_contr_works where pk_contr_works = '"+pk_contr_works+"')";
				BaseDAO dao = new BaseDAO();
				dao.executeUpdate(sql);
			}
		} catch (Exception e) {
			ExceptionUtils.wrappException(e);
		}

	}
}
